package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.Complain;
import cn.gson.springboot.model.service.afterservice.ComplainService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/pla")
public class ComplainController {

    @Autowired
    ComplainService sc;

    @RequestMapping("/plan-page")
    @ResponseBody
    public Map<String,Object> planPage(Integer states,String search,Integer currPage,Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Complain> plan = sc.selectPageHelper(states,search);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;
    }

    @RequestMapping("/save-plan")
    @ResponseBody
    public void savePlan(@RequestBody Complain plan){
        sc.addPlan(plan);
    }

    @RequestMapping("/check-plan")
    @ResponseBody
    public Complain checkPlan(Integer planId){
        return sc.selectPlan(planId);
    }

    @RequestMapping("/delete-plan")
    @ResponseBody
    public void deletePlan(Integer planId){
        sc.deleteByPlanId(planId);
    }

    @RequestMapping("/plan-date")
    @ResponseBody
    public List<Complain> planDate(){
        return sc.selectPlanByDate();
    }

    @RequestMapping("/plan-class")
    @ResponseBody
    public List<Complain> planClass(){
        return sc.selectPlanByClass();
    }

    @RequestMapping("/date-month")
    @ResponseBody
    public List<String> dateMonth(){
        return sc.selectDateByMonth();
    }

    @RequestMapping("/date-count")
    @ResponseBody
    public List<Integer> dateCount(){
        return sc.selectDateByCount();
    }

    @RequestMapping("/custom-name")
    @ResponseBody
    public List<String> customName(){
        return sc.selectCustomByName();
    }

    @RequestMapping("/custom-count")
    @ResponseBody
    public List<Integer> customCount(){
        return sc.selectCustomByCount();
    }
}
